using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLIEFAD
    {
        public DataRow Convert2LIEFAD(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLIEFAD(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LSAMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LSALIEFNR"] = " ".PadRight(8 ); 
         dwReturn["LSAADRSL"] = " ".PadRight(8 ); 
         dwReturn["LSASPRACHKZ"] = " ".PadRight(1 ); 
         dwReturn["LSAANREDE"] = " ".PadRight(1 ); 
         dwReturn["LSANAME1"] = " ".PadRight(40 ); 
         dwReturn["LSANAME2"] = " ".PadRight(40 ); 
         dwReturn["LSASTRASSE1"] = " ".PadRight(40 ); 
         dwReturn["LSASTRASSE2"] = " ".PadRight(40 ); 
         dwReturn["LSALAND"] = " ".PadRight(3 ); 
         dwReturn["LSAPLZ"] = " ".PadRight(12 ); 
         dwReturn["LSAORT"] = " ".PadRight(40 ); 
         dwReturn["LSAPOSTF"] = " ".PadRight(15 ); 
         dwReturn["LSAPLZPOSTF"] = " ".PadRight(12 ); 
         dwReturn["LSACOUNTY"] = " ".PadRight(4 ); 
         dwReturn["LSACITY"] = " ".PadRight(4 ); 
         dwReturn["LSATEL"] = " ".PadRight(20 ); 
         dwReturn["LSATELEX"] = " ".PadRight(20 ); 
         dwReturn["LSAFAX"] = " ".PadRight(20 ); 
         dwReturn["LSABTX"] = " ".PadRight(40 ); 
         dwReturn["LSABEM"] = " ".PadRight(40 ); 
         dwReturn["LSAAPNA1"] = " ".PadRight(40 ); 
         dwReturn["LSAAPBEZ1"] = " ".PadRight(40 ); 
         dwReturn["LSAAPTEL1"] = " ".PadRight(20 ); 
         dwReturn["LSAAPNA2"] = " ".PadRight(40 ); 
         dwReturn["LSAAPBEZ2"] = " ".PadRight(40 ); 
         dwReturn["LSAAPTEL2"] = " ".PadRight(20 ); 
         dwReturn["LSAADRV1"] = " ".PadRight(8 ); 
         dwReturn["LSAADRV2"] = " ".PadRight(8 ); 
         dwReturn["LSAADRRUECK"] = " ".PadRight(8 ); 
         dwReturn["LSAKONDSL"] = " ".PadRight(4 ); 
         dwReturn["LSALO"] = " ".PadRight(2 ); 
         dwReturn["LSALB"] = " ".PadRight(2 ); 
         dwReturn["LSALP"] = " ".PadRight(8 ); 
         dwReturn["LSAUIDNR"] = " ".PadRight(20 ); 
         dwReturn["LSAMOBIL"] = " ".PadRight(20 ); 
         dwReturn["LSAMAILADR"] = " ".PadRight(40 ); 
         dwReturn["LSAILN"] = " ".PadRight(13 ); 
         dwReturn["LSAFILLER"] = " ".PadRight(31 ); 
         dwReturn["LSAAENZL"] = " ".PadRight(0 ); 
         dwReturn["LSAAENB"] = " ".PadRight(8 ); 
         dwReturn["LSAAEND"] = " ".PadRight(0 ); 
         dwReturn["LSANEUB"] = " ".PadRight(8 ); 
         dwReturn["LSANEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLIEFAD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLIEFAD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLIEFAD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLIEFAD(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLIEFAD(dwLocal, ITXDBVERSION);
            }
            UpdateLIEFAD(dwLocal);
        }
        public void InsertLIEFAD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LIEFAD(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLIEFAD(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LIEFAD WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LIEFAD  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LIEFAD";
            Return = Result;
            return Return;
        }
        public void DeleteLIEFAD(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LIEFAD   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLIEFAD(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LIEFAD SET "
                    +"LSAMANDANT= :LSAMANDANT,"
                    +"LSALIEFNR= :LSALIEFNR,"
                    +"LSAADRSL= :LSAADRSL,"
                    +"LSASPRACHKZ= :LSASPRACHKZ,"
                    +"LSAANREDE= :LSAANREDE,"
                    +"LSANAME1= :LSANAME1,"
                    +"LSANAME2= :LSANAME2,"
                    +"LSASTRASSE1= :LSASTRASSE1,"
                    +"LSASTRASSE2= :LSASTRASSE2,"
                    +"LSALAND= :LSALAND,"
                    +"LSAPLZ= :LSAPLZ,"
                    +"LSAORT= :LSAORT,"
                    +"LSAPOSTF= :LSAPOSTF,"
                    +"LSAPLZPOSTF= :LSAPLZPOSTF,"
                    +"LSACOUNTY= :LSACOUNTY,"
                    +"LSACITY= :LSACITY,"
                    +"LSATEL= :LSATEL,"
                    +"LSATELEX= :LSATELEX,"
                    +"LSAFAX= :LSAFAX,"
                    +"LSABTX= :LSABTX,"
                    +"LSABEM= :LSABEM,"
                    +"LSAAPNA1= :LSAAPNA1,"
                    +"LSAAPBEZ1= :LSAAPBEZ1,"
                    +"LSAAPTEL1= :LSAAPTEL1,"
                    +"LSAAPNA2= :LSAAPNA2,"
                    +"LSAAPBEZ2= :LSAAPBEZ2,"
                    +"LSAAPTEL2= :LSAAPTEL2,"
                    +"LSAADRV1= :LSAADRV1,"
                    +"LSAADRV2= :LSAADRV2,"
                    +"LSAADRRUECK= :LSAADRRUECK,"
                    +"LSAKONDSL= :LSAKONDSL,"
                    +"LSALO= :LSALO,"
                    +"LSALB= :LSALB,"
                    +"LSALP= :LSALP,"
                    +"LSAUIDNR= :LSAUIDNR,"
                    +"LSAMOBIL= :LSAMOBIL,"
                    +"LSAMAILADR= :LSAMAILADR,"
                    +"LSAILN= :LSAILN,"
                    +"LSAFILLER= :LSAFILLER,"
                    +"LSAAENZL= :LSAAENZL,"
                    +"LSAAENB= :LSAAENB,"
                    +"LSAAEND= :LSAAEND,"
                    +"LSANEUB= :LSANEUB,"
                    +"LSANEUD= :LSANEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LSAMANDANT", OracleType.NVarChar).Value = dwData["LSAMANDANT"].ToString(); 
          or1.Parameters.Add("LSALIEFNR", OracleType.NVarChar).Value = dwData["LSALIEFNR"].ToString(); 
          or1.Parameters.Add("LSAADRSL", OracleType.NVarChar).Value = dwData["LSAADRSL"].ToString(); 
          or1.Parameters.Add("LSASPRACHKZ", OracleType.NVarChar).Value = dwData["LSASPRACHKZ"].ToString(); 
          or1.Parameters.Add("LSAANREDE", OracleType.NVarChar).Value = dwData["LSAANREDE"].ToString(); 
          or1.Parameters.Add("LSANAME1", OracleType.NVarChar).Value = dwData["LSANAME1"].ToString(); 
          or1.Parameters.Add("LSANAME2", OracleType.NVarChar).Value = dwData["LSANAME2"].ToString(); 
          or1.Parameters.Add("LSASTRASSE1", OracleType.NVarChar).Value = dwData["LSASTRASSE1"].ToString(); 
          or1.Parameters.Add("LSASTRASSE2", OracleType.NVarChar).Value = dwData["LSASTRASSE2"].ToString(); 
          or1.Parameters.Add("LSALAND", OracleType.NVarChar).Value = dwData["LSALAND"].ToString(); 
          or1.Parameters.Add("LSAPLZ", OracleType.NVarChar).Value = dwData["LSAPLZ"].ToString(); 
          or1.Parameters.Add("LSAORT", OracleType.NVarChar).Value = dwData["LSAORT"].ToString(); 
          or1.Parameters.Add("LSAPOSTF", OracleType.NVarChar).Value = dwData["LSAPOSTF"].ToString(); 
          or1.Parameters.Add("LSAPLZPOSTF", OracleType.NVarChar).Value = dwData["LSAPLZPOSTF"].ToString(); 
          or1.Parameters.Add("LSACOUNTY", OracleType.NVarChar).Value = dwData["LSACOUNTY"].ToString(); 
          or1.Parameters.Add("LSACITY", OracleType.NVarChar).Value = dwData["LSACITY"].ToString(); 
          or1.Parameters.Add("LSATEL", OracleType.NVarChar).Value = dwData["LSATEL"].ToString(); 
          or1.Parameters.Add("LSATELEX", OracleType.NVarChar).Value = dwData["LSATELEX"].ToString(); 
          or1.Parameters.Add("LSAFAX", OracleType.NVarChar).Value = dwData["LSAFAX"].ToString(); 
          or1.Parameters.Add("LSABTX", OracleType.NVarChar).Value = dwData["LSABTX"].ToString(); 
          or1.Parameters.Add("LSABEM", OracleType.NVarChar).Value = dwData["LSABEM"].ToString(); 
          or1.Parameters.Add("LSAAPNA1", OracleType.NVarChar).Value = dwData["LSAAPNA1"].ToString(); 
          or1.Parameters.Add("LSAAPBEZ1", OracleType.NVarChar).Value = dwData["LSAAPBEZ1"].ToString(); 
          or1.Parameters.Add("LSAAPTEL1", OracleType.NVarChar).Value = dwData["LSAAPTEL1"].ToString(); 
          or1.Parameters.Add("LSAAPNA2", OracleType.NVarChar).Value = dwData["LSAAPNA2"].ToString(); 
          or1.Parameters.Add("LSAAPBEZ2", OracleType.NVarChar).Value = dwData["LSAAPBEZ2"].ToString(); 
          or1.Parameters.Add("LSAAPTEL2", OracleType.NVarChar).Value = dwData["LSAAPTEL2"].ToString(); 
          or1.Parameters.Add("LSAADRV1", OracleType.NVarChar).Value = dwData["LSAADRV1"].ToString(); 
          or1.Parameters.Add("LSAADRV2", OracleType.NVarChar).Value = dwData["LSAADRV2"].ToString(); 
          or1.Parameters.Add("LSAADRRUECK", OracleType.NVarChar).Value = dwData["LSAADRRUECK"].ToString(); 
          or1.Parameters.Add("LSAKONDSL", OracleType.NVarChar).Value = dwData["LSAKONDSL"].ToString(); 
          or1.Parameters.Add("LSALO", OracleType.NVarChar).Value = dwData["LSALO"].ToString(); 
          or1.Parameters.Add("LSALB", OracleType.NVarChar).Value = dwData["LSALB"].ToString(); 
          or1.Parameters.Add("LSALP", OracleType.NVarChar).Value = dwData["LSALP"].ToString(); 
          or1.Parameters.Add("LSAUIDNR", OracleType.NVarChar).Value = dwData["LSAUIDNR"].ToString(); 
          or1.Parameters.Add("LSAMOBIL", OracleType.NVarChar).Value = dwData["LSAMOBIL"].ToString(); 
          or1.Parameters.Add("LSAMAILADR", OracleType.NVarChar).Value = dwData["LSAMAILADR"].ToString(); 
          or1.Parameters.Add("LSAILN", OracleType.NVarChar).Value = dwData["LSAILN"].ToString(); 
          or1.Parameters.Add("LSAFILLER", OracleType.NVarChar).Value = dwData["LSAFILLER"].ToString(); 
          or1.Parameters.Add("LSAAENZL", OracleType.NVarChar).Value = dwData["LSAAENZL"].ToString(); 
          or1.Parameters.Add("LSAAENB", OracleType.NVarChar).Value = dwData["LSAAENB"].ToString(); 
          or1.Parameters.Add("LSAAEND", OracleType.NVarChar).Value = dwData["LSAAEND"].ToString(); 
          or1.Parameters.Add("LSANEUB", OracleType.NVarChar).Value = dwData["LSANEUB"].ToString(); 
          or1.Parameters.Add("LSANEUD", OracleType.NVarChar).Value = dwData["LSANEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
